package com.wang.mandkey.activity;

import java.util.ArrayList;
import java.util.List;

import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
import android.widget.Button;
import android.widget.ListView;
import android.widget.Toast;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.AdapterView.OnItemLongClickListener;

import com.wang.mandkey.R;
import com.wang.mandkey.bean.AdapterCase;
import com.wang.mandkey.tool.SeariesTool;
import com.wang.mandkey.tool.Tool;
import com.wang.mandkey.utils.ProjectEnvironment;
import com.wang.mandkey.views.PointFBean;

public class Forward2KeyBoardActivity extends BaseActivity {
	
	private ListView mListViewCaseList;
	private Button mButton2KeyBoard;
	private ArrayList<PointFBean> mArrayListpf; 
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setUpView();
	}
	
	@Override
	void setUpView() {
		setContentView(R.layout.forward);
		mListViewCaseList=(ListView)findViewById(R.id.listViewHistoryCase);
		
		final List<String> pfl = SeariesTool.loadCaseList(this);
		
		AdapterCase adapter=new AdapterCase(this, pfl);
		mListViewCaseList.setAdapter(adapter);
		
		mListViewCaseList.setOnItemClickListener(new OnItemClickListener() {
			@Override
			public void onItemClick(AdapterView<?> parent, View view,int position, long id) {
				String caseFileName = pfl.get(position);
				Tool.startOtherActivity2(Forward2KeyBoardActivity.this, KeyBoardActivity.class, ProjectEnvironment.STRING_CASE_KEY, caseFileName);
			}
		});
		
		mListViewCaseList.setOnItemLongClickListener(new OnItemLongClickListener() {
			@Override
			public boolean onItemLongClick(AdapterView<?> parent, View view,int position, long id) {
				String caseFileName = pfl.get(position);
				SeariesTool.deletePointFList(Forward2KeyBoardActivity.this, caseFileName);
				
				List<String> pfl = SeariesTool.loadCaseList(Forward2KeyBoardActivity.this);
				AdapterCase adapter=new AdapterCase(Forward2KeyBoardActivity.this, pfl);
				mListViewCaseList.setAdapter(adapter);
				Toast.makeText(Forward2KeyBoardActivity.this, "已删除:"+caseFileName, Toast.LENGTH_SHORT).show();
				return true;
			}
		});
		
		mButton2KeyBoard=(Button)findViewById(R.id.buttonLink2KeyBoard);
		mButton2KeyBoard.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				Tool.startOtherActivity(Forward2KeyBoardActivity.this, KeyBoardActivity.class);
			}
		});
		
	}
}
